/*
 * Copyright (c) 2008 Ricardo Rocha, rocha.porto@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.gliding.kumulus.client.model;

import java.util.Date;

import com.google.gwt.user.client.Cookies;

/**
 * Definition of a KumulusContext object.
 * 
 * It contains all the generic model data of the Kumulus application, including the currently
 * active user session, etc.
 * 
 * @author Ricardo Rocha <rocha.porto@gmail.com>
 * @version $Rev:: $
 */
public class KumulusContext {

    private static KumulusContext singleton;
    
	/**
	 * Class constructor.
	 */
	private KumulusContext() {
		Cookies.setCookie("KumulusLoggedMemberID", "2", new Date((long)new Date().getTime() + 10000));
	}
	
	public int loggedMemberID() {
		return new Integer(Cookies.getCookie("KumulusLoggedMemberID")).intValue();
	}
	
	public boolean isLogged(int memberID) {
		if (memberID == new Integer(Cookies.getCookie("KumulusLoggedMemberID")).intValue()) {
			return true;
		}
		return false;
	}
	
	public void logout() {
		Cookies.removeCookie("KumulusLoggedMemberID");
	}
	
	public void login(String name, String password) {
		
	}
	
	public static KumulusContext getKumulusContext() {
		if (singleton == null) {
			KumulusContext.singleton = new KumulusContext();
		}
	    return singleton;
	}
	
}
